import VueRouter from 'vue-router'
import Vue from 'vue'

// import home from '../components/home.vue'
// import about from '../components/about.vue'
// import user from '../components/user'

//懒加载
const home=()=>import('../components/home.vue')
const about=()=>import('../components/about.vue')
const user=()=>import('../components/user.vue')

const news=()=>import('../components/homenew')
const messages=()=>import('../components/homemessage')
const profile=()=>import('../components/profile')

//安装插件
Vue.use(VueRouter)

//创建映射关系
const routes=[
  {
    path:'',
    redirect:'/home',

  },
  {
    path:'/home',
    component:home,
    meta:{
      title:'首页'
    },
    children:[
      {
        path:'',
        redirect:'news'
      },
      {
        path:'news',
        component:news
      },
      {
        path:'message',
        component:messages
      }
    ]
  },
  {
    path:'/about',
    component: about,
    meta:{
      title:'关于'
    }
  },
  {
    path:'/user/:username',
    component: user,
    meta:{
      title:'用户'
    }
  },
  {
    path:'/profile',
    component: profile,
    meta:{
      title:'档案'
    }
  },

]


const router=new VueRouter(
    {
      routes,
      mode:'history',
      linkActiveClass:'activate'
    }
)

router.beforeEach((to,from,next)=>{
  document.title=to.matched[0].meta.title
  next()
})

//将router对象传入到vue实例
export default router